import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { EntityHelper } from 'src/utils/entity-helper';
import { AdminUser } from '../../admin-users/entities/admin-user.entity';

@Entity('permission')
export class Permission extends EntityHelper {
	@PrimaryGeneratedColumn()
	id: number;

	@Column()
	name: string;

	@Column()
	resource: string;

	@Column()
	description?: string;

	@Column({ name: 'parent_id' })
	parentId?: number;

	@Column({ name: 'creator_id' })
	creatorId: string;

	@CreateDateColumn({ name: 'create_time' })
	createTime!: Date;

	@UpdateDateColumn({ name: 'update_time' })
	updateTime!: Date;

	@ManyToOne((type) => AdminUser, (userAdmin) => userAdmin.userId)
	@JoinColumn({ name: 'creator_id' })
	user: AdminUser;
}
